// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { selfCls } from "../../../lib/common/Decorator";
import ResMgr from "../../../lib/common/ResMgr";
import CCMP from "../../../lib/object/CCMP";

export interface RenderArgs {
    path:string;
}

const {ccclass, property} = cc._decorator;

@selfCls
export default class Render extends CCMP {

    async init(args?: RenderArgs): Promise<void> {
        await this.loadRender(args.path);
    }

    async loadRender(path:string) {
        return new Promise<void>((resolve, reject)=>{
            ResMgr.loadPrefab(path, (prefab)=>{
                let ins = cc.instantiate(prefab);
                ins.name = "Render";
                this.node.addChild(ins);
                resolve();
            })
        })
    }
}
